// FoodsRecipeController.java
package com.example.controller;

import com.example.entity.FoodsRecipe;
import com.example.service.FoodsRecipeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/foodsrecipe")
public class FoodsRecipeController {
    @Autowired
    private FoodsRecipeService foodsRecipeService;

    @GetMapping("/list")
    public String list(Model model) {
        List<FoodsRecipe> foodsrecipes = foodsRecipeService.getAllFoodsRecipe();
        model.addAttribute("foodsrecipes", foodsrecipes); // 建议使用复数名
        return "foodsrecipe/list";
    }

    @GetMapping("/view/{foodsrecipeId}")
    public String view(@PathVariable Integer foodsrecipeId, Model model) {
        FoodsRecipe recipe = foodsRecipeService.getFoodsRecipeById(foodsrecipeId);
        model.addAttribute("foodsrecipe", recipe);
        return "foodsrecipe/view";
    }
}